package com.loveshes.springbootstudy1.controller;

import com.loveshes.springbootstudy1.bean.demo.UserDemo;
import com.loveshes.springbootstudy1.common.JsonData;
import com.loveshes.springbootstudy1.common.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Hello
 *
 * @Author WangZhe
 * @Date 2021-12-18 21:37
 */
@RestController
@RequestMapping("hello")
public class HelloController {

    @RequestMapping("test1")
    public String test1() {
        return "test1";
    }

    // 不推荐
    @RequestMapping("test2")
    public String test2() {
        return "{\"name\": \"王饱饱\", \"age\": 26}";
    }

    // 最常用
    @RequestMapping("test3")
    public UserDemo test3() {
        UserDemo user = new UserDemo();
        user.setName("王饱饱");
        user.setAge(26);
        return user;
    }

    // 不确定数据结构
    @RequestMapping("test4")
    public Map<String, Object> test4() {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "王饱饱");
        map.put("age", 26);
        return map;
    }

    @RequestMapping("test5")
    public JsonData<UserDemo> test5() {
        UserDemo user = new UserDemo();
        user.setName("王饱饱");
        user.setAge(26);
        JsonData<UserDemo> jsonData = new JsonData<>();
        jsonData.setStatus(0);
        jsonData.setData(user);
        return jsonData;
    }

    // 推荐
    @RequestMapping("test6")
    public JsonData<UserDemo> test6() {
        UserDemo userDemo = new UserDemo();
        userDemo.setName("王饱饱");
        userDemo.setAge(26);
        return JsonResult.<UserDemo>success().data(userDemo);
    }

}
